import { getOrganizationExcelApi } from "@/api/organization";
import { Button } from "antd"
import { utils, writeFile } from "xlsx";
const OrganizationManage = () => {
  const onExport = () => {
    //导出数据
    const data = [
      ['编号', '姓名', '年龄'],
      ['001', '张三', 30],
      ['002', '李四', 30],
      ['003', '王五', 30],
      ['004', '赵六', 30],
      ['005', '爱新觉罗qi', 30]
    ];
    // excel文件中的工作表
    const sheet = utils.aoa_to_sheet(data);
    // 创建一个excel文件
    const book = utils.book_new();
    // 将工作表添加到excel文件中
    utils.book_append_sheet(book, sheet, '表1');
    writeFile(book, '员工信息表.xlsx');

  }
  const getExcelData = () => {
    getOrganizationExcelApi().then(res => {
      if (res.code == 200) {
        console.log(res);
        const aElement = document.createElement('a');
        aElement.href = res.data;
        aElement.click();
      }
    })
  }
  return (
    <>
      <div>组织管理</div>
      <Button onClick={onExport}>
        导出
      </Button>
      <Button onClick={getExcelData}>
        后端导出
      </Button>
    </>
  )
}

export default OrganizationManage